import os
from fastapi import APIRouter
from fastapi import APIRouter, HTTPException
from api.application.utils.logs import getLogger
from api.application.utils.deepseek import chat, models
from fastapi.responses import JSONResponse
from fastapi import status
from pydantic import BaseModel

app = APIRouter()


@app.get('/api')
async def api() -> dict:
	"""
	测试接口
	:return:
	"""
	return {'title': f'{os.environ.get("APP_NAME")}测试接口'}


@app.get('/exception')
async def exception(name: str) -> dict:
	"""测试异常接口"""
	try:
		print(username)
	except Exception as e:
		logger = getLogger(os.environ.get('APP_NAME'))
		logger.error(f"发生错误：{e}")
		raise HTTPException(detail = f"{e}", status_code = 500)
	return {}


class Message(BaseModel):
	msg: str
	model: str


@app.post('/deepseek-chat')
async def deepseek_chat(message: Message) -> JSONResponse:
	response = chat(msg = message.msg, model = message.model)
	# response = '你好，我是deepseek请问有什么可以帮到您'
	return JSONResponse({
		'code': 0,
		'err_msg': '',
		'status': 'Success',
		'data': {
			'response': response
		}
	})


@app.get('/deepseek-models')
async def deepseek_models() -> JSONResponse:
	response = models()
	return JSONResponse({
		'code': 0,
		'err_msg': '',
		'status': 'Success',
		'data': response
	})
